import offer.TreeNode;

/**
 * @Author: wangliuyang
 * @Date: 2021/6/14 13:43
 * @Description: 222. 完全二叉树的节点个数
 */
public class Solutions222 {
    public int countNodes(TreeNode root) {
        int count = 0;
        if (root == null) {
            return 0;
        }
        int left = getLength(root.left);
        int right = getLength(root.right);
        if (left == right) {
            count = countNodes(root.right) + (1 << left);
        }else {
            count = countNodes(root.left) + (1 << right);
        }
        return count;
    }
    //因为为完全二叉树，所以左数长度不小于右数长度
    public int getLength(TreeNode node) {
        if (node == null) {
            return 0;
        }
        return getLength(node.left) + 1;
    }

    public static void main(String[] args) {
        System.out.println(2>> 1);
    }
}
